﻿using DosTexPrj.Core.Models;
using FluentNHibernate.Mapping;

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    public class YarnOrderMapping : ClassMap<YarnOrder>
    {
        public YarnOrderMapping()
        {
            Table("YarnOrders");
            Id(x => x.Id, "YarnOrderID").UnsavedValue(0).GeneratedBy.Identity();
            Map(x => x.OrderDate, "OrderDate").Not.Nullable();
            Map(x => x.DeliveryDate, "DeliveryDate").Not.Nullable();
            Map(X => X.IsDeliveredBefore, "IsDeliveredBefore");
            Map(x => x.NumberOfDateExtensionDelivery, "NumberOfDateExtensionDelivery");
            Map(x => x.DeliveryAddress, "DeliveryAddress").Not.Nullable().Length(200);
            References<Supplier>(x => x.Supplier).Not.LazyLoad().Column("SupplierID");
            References<OrderStatus>(x => x.OrderStatus).Not.LazyLoad().Column("OrderStatusID");
            References<PaymentMethod>(x => x.PaymentMethod).Not.LazyLoad().Column("PaymentMethodID");
            References<DeliveryMethod>(x => x.DeliveryMethod).Not.LazyLoad().Column("DeliveryMethodID");
            References<Order>(x => x.BelongToOrder).Not.LazyLoad().Column("OrderID");
            HasMany<YarnOrderDetail>(x => x.YarnOrderDetails).KeyColumn("YarnOrderID")
                                                                .Cascade.AllDeleteOrphan()
                                                                .Not.LazyLoad().AsBag();
        }
    }
}